/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package anotador;

import gate.*;

import gate.creole.*;
import gate.jape.JapeException;
import gate.util.GateException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.*;
import java.util.*;

/**
 *
 * @author Mauricio
 */
public class DefinitionAnnotator {

    private Controller controller;
    private GateCorpus corpus;

    public DefinitionAnnotator()
    {
        try {
            init();
        } catch (GateException ex) {
            ex.printStackTrace();
        }
    }

    private void init() throws GateException
    {
        // INICIAR GATE
        Gate.init();
        try {
            Settings.load("anotador.properties");
                    //"C:\\Documents and Settings\\hayner\\Escritorio\\Patrones2\\Patrones\\src\\anotador\\anotador.properties");
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        }
        /*CreoleRegister creoleRegister = Gate.getCreoleRegister();
        try {
            creoleRegister.addDirectory(new URL("file:C:/GATE-4.0/plugins/NP_Chunking"));
            creoleRegister.addDirectory(new URL("file:C:/GATE-4.0/plugins/Tools"));
        } catch (MalformedURLException ex) {
                ex.printStackTrace();
        }*/
        //CREAR EL CORPUS
        corpus = new GateCorpus();

        //CREAR EL CONTROLADOR
        controller = new Controller();

        //y asignarle el corpus
        controller.setCorpus(corpus);
        
        // añadiendo processing resources
        controller.addDefaults();
        try {
            //gazeteer para terminos
            controller.addGazetteer(new URL("file:\\"+Settings.get("gazetteer")));
            //transducer
            controller.addTransducer((new URL("file:\\"+Settings.get("patrones"))));
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
    }

    public void addDocument(URL url) throws ResourceInstantiationException
    {
        corpus.addDocument(url);
    }

    public void execute() throws ExecutionException, JapeException
    {
        //ejecutar controlador
        controller.execute();
    }

    public void createHTMLs()
    {
        corpus.crearHTMLs();
    }

    public void setOutputAnnotations(ArrayList<String> outputAnnotations) {
        corpus.setOutputAnnotations(outputAnnotations);
    }

}
